﻿using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine;

namespace Yoozoo.Modules.InnerCity
{
    public class BuildAction : ActionBase
    {
        private float buildTime;
        private float hasBuildTime;

        protected override StateAction state
        {
            get => StateAction.Build;
        }

        public override void Init(CityUnit owner)
        {
            base.Init(owner);
        }

        public override void Enter(object args = null)
        {
            Debug.Log("进入了建造状态");
            this.buildTime = args == null ? -1 : (float) args;
            this.hasBuildTime = 0;
            this.owner.PlayBuildAni();
        }

        public override void Play()
        {
            if (this.buildTime == -1)
                return;

            this.hasBuildTime += Time.deltaTime;
            if (hasBuildTime >= this.buildTime)
                this.owner.OnBuildEnd();
        }

        public override void Exit()
        {
            Debug.Log("退出了建造状态");
            base.Exit();
        }
    }
}